<template>
  <el-dialog v-if="visible" :title="info.title" :visible.sync="visible" append-to-body center width="760px" :before-close="handleCancel">
    <el-form ref="formDate" label-suffix=":" label-width="120px" :rules="rules" :model="form">
      <el-row>
        <el-col :span="12">
          <el-form-item label="供应商名称" prop="name">
            <el-input v-model="form.name" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="统一信用代码" prop="credit_code">
            <el-input v-model="form.credit_code" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="注册资金" prop="registered_capital">
            <el-input v-model="form.registered_capital" style="width: 85%" size="small" clearable />万元
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="主营业务" prop="main_business">
            <el-input v-model="form.main_business" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="付款方式" prop="payment">
            <el-select v-model="form.payment" size="small" style="width: 100%">
              <el-option
                v-for="(item, index) in types"
                :key="index"
                :label="item.value"
                :value="index"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="结算周期" prop="settlement_period">
            <el-input v-model="form.settlement_period" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="附件上传" prop="files">
            <Upload v-model="form.files" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" :rows="4" size="small" clearable style="width: 100%" />
          </el-form-item>
        </el-col>
        <!-- <el-col class="mt10" :span="24">
          <el-form-item label="抄送" prop="ccs">
            <VerifyCC v-model="form.ccs" :ccs="ccs" />
          </el-form-item>
        </el-col> -->
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="fr mt10">
            <el-button size="small" @click="handleCancel()">取 消</el-button>
            <el-button type="primary" size="small" @click="handleBeforeTo()">提 交</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
// import VerifyCC from '@/myComponents/VerifyCC'
import { payments } from '@/api/supplier'
import Upload from '@/myComponents/Upload'
import svf from '../../util/svf'

export default {
  components: { Upload },
  extends: svf,
  data() {
    return {
      approve_key: 'PROCESS_SUPPLIER',
      types: [],
      baogao: {},
      rules: {
        name: [{ required: true, trigger: 'blur', message: '供应商名称不可为空' }],
        registered_capital: [{ required: true, trigger: 'blur', message: '注册资金不可为空' }],
        credit_code: [{ required: true, trigger: 'blur', message: '统一信用代码不可为空' }],
        main_business: [{ required: true, trigger: 'blur', message: '主营业务不可为空' }],
        settlement_period: [{ required: true, trigger: 'blur', message: '结算周期不可为空' }],
        payment: [{ required: true, trigger: 'blur', message: '付款方式不可为空' }],
        files: [{ required: true, trigger: 'blur', message: '附件不可为空' }]
      }
    }
  },
  watch: {
    visible(val) {
      if (val) {
        if(this.info.type && this.info.type === 'again'){
          this.initApply(this.info.edit)
        }else{
          this.form = this.info.edit
        }
        this.payments()
        // this.queryCcs()
      }
    }
  },
  mounted() {
  },
  methods: {
    payments() {
      payments().then(response => {
        this.types = response.list
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    handleBeforeTo() {
      this.validate().then(() => {
        const e = {}
        e.files = this.form.files
        e.approve_key = this.approve_key
        e.des = '供应商名称：' + this.form.name + '    备注：' + this.form.remark
        e.ccs = this.form.ccs
        e.forms = JSON.stringify(this.createForms([
          ['供应商名称', this.form.name, this.form.name, 'name'],
          ['统一信用代码', this.form.credit_code, this.form.credit_code, 'credit_code'],
          ['注册资金（万）', this.form.registered_capital, this.form.registered_capital, 'registered_capital'],
          ['主营业务', this.form.main_business, this.form.main_business, 'main_business'],
          ['付款方式', this.types[this.form.payment]['value'], this.types[this.form.payment]['key'], 'payment'],
          ['结算周期', this.form.settlement_period, this.form.settlement_period, 'settlement_period'],
          ['备注', this.form.remark, this.form.remark, 'remark']
        ]))
        this.handleCreate(e)
      })
    }
  }
}
</script>

<style>
</style>
